﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MsTestUtilities.SolutionAnalysis.Testing;
using MsTestUtilities.SolutionAnalysis;
using MsTestUtilities;

namespace MsTestUtilitiesTests.SolutionAnalysisTests.Testing.BuildConfigurationAssertTests
{
    [TestClass]
    public class WarningTreatedAsErrorsTests
    {
        private BuildConfigurationAssert _assert;
        private BuildConfigurationFake _buildConfiguration;

        [TestInitialize]
        public void Setup()
        {
            _buildConfiguration = new BuildConfigurationFake
            {
                Name = "Config"
            };
            _assert = new BuildConfigurationAssert(new []{_buildConfiguration});
        }

        [TestMethod]
        public void WarningsTreatedAsErrors_Passes()
        {
            _buildConfiguration.TreatWarningsAsErrors = true;
            _assert.WarningsTreatedAsErrors();
        }

        [TestMethod]
        public void WarningsNotTreatedAsErrors_Fail()
        {
            _buildConfiguration.TreatWarningsAsErrors = false;

            const string expectedMessage = "Fake Project > Config: Warnings not treated as errors.";
            ExAssert.Throws<AssertFailedException>(_assert.WarningsTreatedAsErrors, e => e.Message.Contains(expectedMessage));
        }
    }
}
